import React from 'react';
import FloatLayout from '../_/floatLayout';
import PatientForm from './myPatientForm';

export default class myPatientEdit extends React.Component {
    static _data = {};
    state = {
        show: this.props.show,
        title: this.props.title,
        relative: this.props.relative,
        reset: false
    };

    componentWillReceiveProps(nextProp) {
        if (nextProp.isNew) {
            this.setState({
                reset: true
            });
        }
        this.setState({
            show: nextProp.show
        });
    }

    hideEditor() {
        if (typeof this.props.hideEditor === 'function') {
            this.props.hideEditor();
        }
        this.setState({
            reset: true
        });
    }

    doneReset = () => {
        this.setState({
            reset: false
        });
    };

    render() {
        return (
            <FloatLayout
                show={this.state.show}
                title={this.state.title}
                relative={this.state.relative}
                left="214px"
                top="48px"
                closed={this.hideEditor.bind(this)}
            >
                <PatientForm hideEditor={this.hideEditor.bind(this)} dataEdit={this.props.dataEdit} reset={this.state.reset} doneReset={this.doneReset}/>
            </FloatLayout>
        );
    }
}
